<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/pc/jsp/common/common.jsp"%>
<%@ page import="com.limao.DBDataClass.CrowdSysProjectClass" %>
<%@ page import="com.limao.CacheManager.CrowdSysProjectCache" %>
<%@ page import="com.wsu.search.tools.Tools" %>
<%
 	 String userid=(String)CacheClass.isLogin(request,response);
	 if(CacheClass.getIntValue(userid)==0)
	 {
	 	out.println("<script language='JavaScript'>alert('您还没有登陆！');location.href=document.referrer;</script>"); //后退并刷新
	 } 
    String projectid = request.getParameter("projectid");
    if(CacheClass.isEmpty(projectid))
    {
 		out.println("<script language='JavaScript'>alert('参数不正确！');location.href=document.referrer;</script>"); //后退并刷新
 	}
    CrowdSysProjectClass crowd = CrowdSysProjectCache.getInstance().load_Goods_Info_ById(CacheClass.getIntValue(projectid));
    if(crowd==null)
    {
 		out.println("<script language='JavaScript'>alert('商品不存在或已下架！');location.href=document.referrer;</script>"); //后退并刷新
 	}
    
    String num = request.getParameter("num");
    if(CacheClass.isEmpty(num))
    	num="1";
    String selectextra = request.getParameter("selectextra");
    if(!CacheClass.isEmpty(selectextra))
    	selectextra = new String(selectextra.getBytes("iso-8859-1"),"utf-8");
    else
    	selectextra="";

%>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <title>支付--收货地址</title>
    <link rel="stylesheet" href="js/validation/screen.css" />
    <script src="js/validation/jquery.js"></script>
    <script src="js/validation/jquery.validate.js"></script>
    <script src="js/validation/messages_zh.js"></script>
    <script src="pc/js/jquery.cityselect.js"></script>
    <script>
		$(window).load(function() {
			headertabcurrent=1;
			$("#header").load("pc/header.jsp"); 
			$("#footer").load("pc/footer.jsp"); 
			
			//headerTab(1);
		});
	</script>
</head>
<body  ontouchstart="">
    <div class="theme-popover-mask"></div>
        <!--header-->
	<div  id="header"> </div>

    <div class="container jz bcf" style="margin-top: 18px;">
    
    
        
        <div class="fqzcTittle jz of clearfix">
             <div class="fl f20 c3">
             		确定购买<span class="f16 c9" style="margin-left: 20px">（可返回上级修改）</span>
             </div>
		</div>
		<div class="ishenqing jz of">
		           <div class="zcDiv clearfix of" style='line-height:37px;'>
                        <span class="f17 fb c3 fl dib">商品名称</span>
                         <div class="fl tl cblue mgl10"  style='line-height:29px'>
                            <span class="f16"></span><span class="f24" ><%=crowd.projectname%></span><span class="f20"></span>                      
                        </div>
                    </div>
                    <div class="w100 dashLine" style="margin-top: 8px;margin-bottom: 15px;"></div>
                     <div class="zcDiv clearfix of" style='line-height:30px;'>
                        <span class="f17 fb c3 fl dib">单价</span>
                         <div class="fl tl cblue mgl10"  style='line-height:30px'>
                            <span class="f16">¥</span><span class="f30" id="pgprice"><%=crowd.packageprice%></span><span class="f20"></span>                      
                        </div>
                        <p class="fr c3 f16" style="right:0;top:0">数量：<span class="c9 f14 mgl10"><%=num%></span></p>
                    </div>
                    <div class="w100 dashLine" style="margin-top: 8px;margin-bottom: 15px;"></div>
                    <div class="zcDiv clearfix of" style='line-height:37px;'>
                        <span class="f17 fb c3 fl dib">总额</span>
                         <div class="fl tl cred mgl10"  style='line-height:29px'>
                            <span class="f16">¥</span><span class="f30" id="pgprice"><%=(CacheClass.getIntValue(num)*CacheClass.getFloatValue(crowd.packageprice))%></span><span class="f16">(配送费:免费)</span>                      
                        </div>
                        <p class="fr c3 f16" style="right:0;top:0">规格：<span class="c9 f14 mgl10"><%if(CacheClass.isEmpty(selectextra)){%>无<%}else{%><%=selectextra%><%}%></span></p>
                    </div>                 
					<div class="w100 dashLine" style="margin-top: 8px;margin-bottom: 15px;"></div>
                    <div class="zcDiv w100">
                       	<p class="f17 fb c3 mgt18">支付方式</p>
                        <div class="w100 dashLine" style="margin-top: 8px;margin-bottom: 15px;"></div>
                        <div id="payWay" class="payWay2 w100 clearfix of">
                            <div class="clearfix of">
                                <div class="br3 fl payCurrent">支付宝</div>
                                <div class="br3 fr">微信</div>
                            </div>
                            <div class="clearfix of mgt10 mgb18">
                            	<div class="br3 fl">银联</div>
                                <div class="br3 fr">余额</div>
                            </div>
                            
                            <!-- 
                            <div class="clearfix of mgt10 mgb18">
                            	<div class="br3 fl">爱贝</div>
                            </div>
                             -->
                        </div>
                    </div>
   

                </div>    
    
    
        <div class="w100 of bcf">
            <div class="fqzcTittle jz of clearfix">
                <div class="fl f20 c3">
                    收货地址<span class="f16 c9" style="margin-left: 20px">（必须填写真实有效资料）</span>
                </div>

            </div><!--fqzcTittle-->
            <div class="w100 of">
            <form  method="post" id="signupForm" action="" >
                <div class="ishenqing jz of">
                   
                    <div class="zcDiv clearfix">
                        <label for="city_3" class="IDcard f18 fl"><img src="pc/images/xing.png" class="xing dib pr">所在地</label>
                        <div id="city_3" class="fr">
                            <div class="w100 clearfix pr">
                                <div class="fl f16">
                                    <select class="prov" id="prov"  name="prov" required="required"></select>&nbsp;(省份)
                                </div>
                                <div class="fr f16" style="margin-left: 38px">
                                    <select class="city" id="city" name="city" disabled="disabled" required="required"></select>&nbsp;(城市)
                                </div>
                            </div>
                        </div> <!--city_3-->
                        <script src="js/jquery.cityselect.js"></script>
                        <script>
                            $(function () {
                                $("#city_3").citySelect({required: false});
                            })
							
                        </script>
                    </div>
                    <div class="pr">
	                    <div class="zcDiv clearfix of">
	                        <textarea id="detailAddress" name="detailAddress" class="zcInput fr" placeholder="详细地址" style="min-height: 110px;padding-top: 10px;padding-bottom: 10px;"></textarea>
	                    </div>
                    </div>
					<div class="pr">
						<div class="zcDiv clearfix of pr">
	                        <label for="user_name" class="IDcard f18 fl"><img src="pc/images/xing.png" class="xing dib pr">联系人</label>
	                        <input type="text" name="user_name" id="user_name"  class="zcInput fr" placeholder="真实姓名"/>
	                    </div>
					</div>
                    <div class="pr">
	                     <div class="zcDiv clearfix of pr">
	                        <label for="usertel" class="IDcard f18 fl"><img src="pc/images/xing.png" class="xing dib pr">联系电话</label>
	                        <input type="text" name="usertel" id="usertel" class="zcInput fr" placeholder="联系电话"/>
	                    </div>
                    </div>
                   
                </div><!--ishenqing-->
                </form>
            </div>
            
                   <div class="w100 dashLine" style="margin-top: 8px;margin-bottom: 15px;"></div>
                     
                    <script type="text/javascript">
                      $(function(){
                       $("#payWay>div>div").bind('click',function () {
                            $("#payWay>div>div").removeClass('payCurrent');
                            $(this).addClass('payCurrent');
                            var payway = $('#payWay .payCurrent').text();
                            if(payway=='支付宝')
                            {
                            	paywayVal=0;
                            }
                            else if(payway=='微信')
                            {
                            	paywayVal=1;
                            }
                            else if(payway=='银联')
                            {
                            	paywayVal=2;
                            }
                            else if(payway=='余额')
                            {
                            	paywayVal=3;
                            }
                            else if(payway=='爱贝')
                            {
                            	paywayVal=4;
                            }
                         })
                              
                               $("#guiGe>div>div").bind('click',function () {
                                    $("#guiGe>div>div").removeClass('payCurrent');
                                    $(this).addClass('payCurrent');
                                    selectextraVal = $('#guiGe .payCurrent').text();
                                })

                                //获得文本框对象
                                var t = $("#count");

                                //数量增加操作
                                $("#add").click(function(){
                                    t.val(parseInt(t.val())+1);
									toTotal();
                                })
                                //数量减少操作
                                $("#minus").click(function(){
                                    if (parseInt(t.val())==1){
                                        return ;
                                    }
                                    t.val(parseInt(t.val())-1);
									toTotal();
                                })
                      })
                       function toTotal()
						 {
						 
						    $("#moneyChange").html($.trim($("#count").val())*1.0*$.trim($("#pgprice").html()));
						 
						 } 
                    </script>
                    <div class="zcDiv w100">
                        <input type="button" onclick="Sub();" name="" id="" value="确认支付" style="margin-top: 130px;" class="fqztSub blueh cursor db jz cf tc f20">
                    </div>
        </div>
        
    </div><!--container-->

	<!--footer-->
    <div id="footer" class="footer w100 of"></div>
    
    <div class="theme-popover-mask"></div>
   <div id="successSub" class="w100 h100 pf">
       <div class="jz of bcf">
            <div class="sqtittle tc jz c3">
                申请提交成功
            </div>
           <p class="successSubP f18 t2">
               您的认证申请已经提交，工作人员在三个工作日对资料进行审核，期间
               请保持通讯顺畅。
           </p>
           <button class="successSubBtn cf tc jz db blueh" onclick="successSubHide();">关闭</button>
       </div>
   </div><!--successSub-->

</body>
<script>
var paywayVal=0;
var myValidator;

 //详细地址过滤下划线等符号
 jQuery.validator.addMethod("isAddress", function(value, element) { 
		var myReg = /^[^_\x22]+$/;
		return this.optional(element) || myReg.test(value); 
	}, "详细地址包含非法符号例如下划线等符号"); 

$().ready(function() {
	 	  myValidator=$("#signupForm").validate(
	 		{
	 			rules:{
  	 				prov: {
                		required:true,
                		isShengcity:true
            		},			
  	 				city: {
                		required:true,
                		isShengcity:true
            		},
            		detailAddress:{
            			required:true,
             			rangelength:[5,80],
             			isAddress:true  
            		},
            		user_name:
            		{
            			required:true,
            			rangelength:[2,15]
            		},
            		usertel:
            		{
            			required:true,
            			digits:true
            			
	 				}
	 			},
	 			//errorElement: 'p',
                errorPlacement: function(error, element) {
                // Append error within linked label
                
                $( element )
	                .closest( "form" )
	                .find( element )
	                .parent("div")
	                .after( error );
                },
                errorElement: "p"
				
	 		});
	 		
        //取上次的收货地址
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 146}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
            },
            success: function (data) {
                console.log(data);
                if (data.state == 1) {
                    // 申请成功 关闭页面 回退
                    if (typeof(data.obj.address) != "undefined") {
                        // 设置默认地址
                        $.getJSON("pc/js/city.min.js", function (json) {
                            $.each(json.citylist, function (i, prov) {
                                if (prov.p.indexOf(data.obj.shengid) != -1) {
                                    $.each(prov.c, function (i, city) {
                                        if (city.n.indexOf(data.obj.cityid) != -1) {
                                            $("#city_3").citySelect({prov: prov.p, city: city.n, required: false});

                                            // 填写详细地址
                                            var sc = prov.p.split('_')[0] + city.n.split('_')[0];
                                            $("#detailAddress").val(data.obj.address.substring(sc.length, data.obj.address.length));
                                        	$("#user_name").val(data.obj.person_name);
                                        	$("#usertel").val(data.obj.tel);
                                        	
                                        	return true;
                                        }
                                    });
                                    return true;
                                }
                            });
                        });
                    }

                } else {
                    // 其他错误弹出提示
                    layer.alert(data.info);
                }
            },
            error: function (data) {
                layer.alert(data.info);
            },
            complete: function () {
            }
        });
    
});

    function successSubHide() {
        $(".theme-popover-mask").fadeOut();
        $("#successSub").slideUp();
    }

 
function Sub() {
    
           console.log(myValidator);
	       if(myValidator.form()== false){
	            layer.alert("填写存在错误 ！");
	            return false;
	        }
            
	        var provVal =$.trim($(".prov").find("option:selected").val());
	        var cityVal =$.trim($(".city").find("option:selected").val());
	        var detailAddress = $.trim($('#detailAddress').val());
	        var usernameVal =$.trim($('#user_name').val());
	        var usertelVal = $.trim($('#usertel').val());
	        addressVal=provVal.split("_")[0]+cityVal.split("_")[0]+detailAddress+"_"+usernameVal+"_"+usertelVal;
	        
	          //按要求过滤
            if(detailAddress.indexOf("_")>-1){
            	 layer.alert("您的详细地址中存在干扰字符，例如（下划线）！");
               	return false;
            }
	        
	        
	        
		if(paywayVal<2)
        {
        	layer.alert("暂不支持，请选择  银联支付 或 余额支付  进行测试。");
        	return;
        }       
        var shengidVal=provVal.split("_")[1];
        var cityVal=cityVal.split("_")[1];
        var projectidVal="<%=projectid%>";
        var selectextraVal="<%=selectextra%>";
        var numVal="<%=num%>";
        
        
        if(paywayVal==10)
        {
            var contentHtml='';
	        contentHtml=contentHtml+'<input type="hidden" name="projectid" id="projectid" value="'+projectidV+'"/>'+
									'<input type="hidden" name="selectextra" id="selectextra" value="'+selectextraVal+'"/>'+
	 								'<input type="hidden" name="num" id="num" value="'+numVal+'"/>'+
	 								'<input type="hidden" name="about" id="about" value=""/>'+ 
	 								'<input type="hidden" name="paytype" id="paytype" value="'+paywayVal+'"/>';       
	        $("#buyForm").html(contentHtml);
	        document.buyForm.submit();
        }
        else
        {
        	if(paywayVal*1.0==2 || paywayVal*1.0==4)
		    {
		        var tempwindow=window.open();
		    }
	         $.ajax({
	            url: "PlugServlet ",
	            data: JSON.stringify({m:1720,projectid :projectidVal,selectextra:selectextraVal,num:numVal,about:'',paytype:paywayVal,apptype:0,address:addressVal,shengid:shengidVal,cityid:cityVal}),
	            type: 'post',
	            dataType: 'json',
	            contentType:"application/json;charset=utf-8",
	            beforeSend: function () {
	                $("#loadingfDiv").fadeIn();
	            },
	            success: function (data) {
	            
	            	console.log(data);
	   	           if(data['state']==1)
		           {
		           		//layer.alert(data.info);
		           		if(data['paytype']*1.0==2)
		           		{
		           			console.log(baseUrl+'pc/unionProPay.jsp?orderid='+data['orderid']);
		           		 	tempwindow.location=baseUrl+'pc/unionProPay.jsp?orderid='+data['orderid'] ;
		           		}
		           		if(data['paytype']*1.0==4)
		           		{
		           		 	tempwindow.location=data['params'] ;
		           		}
		           		else
		           		{
		           			layer.alert(data.info);
		           		}
		           }
		           else
		           {
		           		layer.alert(data.info);
		           }
	           },
	            error: function (data) {
	                layer.alert(data.msg);
	                return false;
	            },
	            complete: function () {
	                $("#loadingfDiv").fadeOut();
	            }
	        }); 
        }
}

</script>

</html>
